package com.tengju.support.domain.model.user;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.tengju.support.domain.shared.IdObject;

import java.util.Objects;

public class UserIdCode extends IdObject {

    /**
     * Instantiates a new Id object.
     *
     * @param value the value
     */

    private static final long serialVersionUID = -4373157387918576605L;

    public UserIdCode(long value) {
        super(value);
    }

    @Override
    @JsonValue
    public long getValue() {
        return super.getValue();
    }

    public static boolean isVirtual(Long value) {
        return value == null || value == 0L;
    }

    @JsonCreator
    public static UserIdCode of(Long value) {
        if (value == null) {
            return null;
        }
        if (isVirtual(value)) {
            return null;
        }
        return new UserIdCode(value);
    }

    public long getAbmUserId() {
        return getValue() - 200000L;
    }

    @Override
    public boolean sameValueAs(IdObject other) {
        return other != null && this.getValue() == other.getValue();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        IdObject idObject = (IdObject) o;
        return sameValueAs(idObject);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.getValue());
    }

}
